﻿/*
 * 由SharpDevelop创建。
 * 用户： Administrator
 * 日期: 2015/9/1 周二
 * 时间: 18:47
 * 
 * 要改变这种模板请点击 工具|选项|代码编写|编辑标准头文件
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;

namespace aa
{
	/// <summary>
	/// Description of MainForm.
	/// </summary>
	public partial class MainForm : Form
	{
		private int [] scores;
		private Image [] images;
		private PictureBox [] picBox;
		public MainForm()
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			
			//
			// TODO: Add constructor code after the InitializeComponent() call.
			//
			this.scores = new int[4];
			this.images = new Image[4];
			
			this.picBox = new PictureBox[4];
			this.picBox[0]=this.pictureBox0;
			this.picBox[1]=this.pictureBox1;
			this.picBox[2]=this.pictureBox2;
			this.picBox[3]=this.pictureBox3;
			
			for (int i =0;i<4;i++){
				this.scores[i]++;
			}
			
			this.images[0]=this.pictureBox0.Image;
			this.images[1]=this.pictureBox1.Image;
			this.images[2]=this.pictureBox2.Image;
			this.images[3]=this.pictureBox3.Image;
			
			this.pictureBox0.Location = new Point(130+55+55/2 - this.pictureBox0.Width/2,this.pictureBox0.Location.Y);
			this.pictureBox1.Location = new Point(130+55*3+55/2 - this.pictureBox0.Width/2,this.pictureBox0.Location.Y);
			this.pictureBox2.Location = new Point(130+55*5+55/2 - this.pictureBox0.Width/2,this.pictureBox0.Location.Y);
			this.pictureBox3.Location = new Point(130+55*7+55/2 - this.pictureBox0.Width/2,this.pictureBox0.Location.Y);
		
		
			this.pictureBox0.MouseDoubleClick += new MouseEventHandler (this.PictureBox0MouseDoubleClick);
			this.pictureBox1.MouseDoubleClick += new MouseEventHandler (this.PictureBox1MouseDoubleClick);
		}
		
		void MainFormLoad(object sender, EventArgs e)
		{
			
		}
		void Button1Click(object sender, EventArgs e)
		{
			
		}
		void MainFormValidated(object sender, EventArgs e)
		{
	
		}
		void MainFormPaint(object sender, PaintEventArgs e)
		{
			Graphics gr = this.CreateGraphics();
			//以下三行画Y轴  450-100
			gr.DrawLine(Pens.Black,100,100,100,450);
			gr.DrawLine(Pens.Black,100,100,90,110);
			gr.DrawLine(Pens.Black,100,100,110,110);
			
			//以下三行画X轴  650-100 550/9
			gr.DrawLine(Pens.Black,100,450,650,450);
			gr.DrawLine(Pens.Black,650,450,640,440);
			gr.DrawLine(Pens.Black,650,450,640,460);
			
			
			gr.FillRectangle(Brushes.Blue,130+55,		450-35*this.scores[0], 55,35*this.scores[0]);
			gr.FillRectangle(Brushes.Yellow,130+55*3,	450-35*this.scores[1], 55,35*this.scores[1]);
			gr.FillRectangle(Brushes.Red,130+55*5,		450-35*this.scores[2], 55,35*this.scores[2]);
			gr.FillRectangle(Brushes.Purple,130+55*7,	450-35*this.scores[3], 55,35*this.scores[3]);
		}
		void PictureBox0MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if(e.Button==MouseButtons.Left){
				this.scores[0]++;
			}else{
				this.scores[0]--;
			}
			if(this.scores[0]>10) this.scores[0]=10;
			if(this.scores[0]<0) this.scores[0]=0;
			
			CheckEachPicBox();
			
			this.Invalidate(null);
		}
		void PictureBox2MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if(e.Button==MouseButtons.Left){
				this.scores[2]++;
			}else{
				this.scores[2]--;
			}
			if(this.scores[2]>10) this.scores[2]=10;
			if(this.scores[2]<0) this.scores[2]=0;
			
			CheckEachPicBox();
			
			this.Invalidate(null);
		}
		void PictureBox1MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if(e.Button==MouseButtons.Left){
				this.scores[1]++;
			}else{
				this.scores[1]--;
			}
			if(this.scores[1]>10) this.scores[1]=10;
			if(this.scores[1]<0) this.scores[1]=0;
			
			CheckEachPicBox();
			
			this.Invalidate(null);
		}
		void PictureBox3MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if(e.Button==MouseButtons.Left){
				this.scores[3]++;
			}else{
				this.scores[3]--;
			}
			if(this.scores[3]>10) this.scores[3]=10;
			if(this.scores[3]<0) this.scores[3]=0;
			
			CheckEachPicBox();
			
			this.Invalidate(null);	
		}
		
		void CheckEachPicBox()
		{
			for(int n=0;n<4;n++){
				int s =this.scores[n];
				if(s<=0){continue;}
				
				int i=0;
				for( i=0;i<4;i++){
					if(this.scores[i]>s){
						this.picBox[n].Image = this.images[n];
						break;
					}
				}
				
				if(i==4){
					this.picBox[n].Image = this.pictureBox4.Image;
				}
				
			}
		}
		
	}
}
